<template>
  <div>
    <h1 style="font-size: 30px;margin-bottom:10px">已发布Blog</h1>
    <el-table
      :data="
        tableData.slice((currentPage - 1) * pageSize, currentPage * pageSize)
      "
      v-loading="loading"
    >
      <el-table-column
        prop="userName"
        label="创建人"
        width="100px"
      ></el-table-column>
      <el-table-column prop="title" label="标题"></el-table-column>
      <el-table-column prop="modifyDate" label="修改日期"></el-table-column>
      <el-table-column prop="readCount" label="阅读次数"></el-table-column>
      <el-table-column fixed="right" label="操作">
        <template slot-scope="scope">
          <el-button @click="preview(scope.row)" type="text" 
            >查看</el-button
          >
          <el-button @click="edit(scope.row)" type="text" 
            >编辑</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      layout="total,sizes, prev, pager, next, jumper"
      :total="total"
      @size-change="handleSizeChange"
      :current-page="currentPage"
      :page-size="pageSize"
      @current-change="handleCurrentChange"
      :page-sizes="[ 4, 8, 12]"
    >
    </el-pagination>
  </div>
</template>

<script>
export default {
  name: "CheckBlog",
  data() {
    return {
      tableData: [],
      isDraft: 0,
      loading: true,
      currentPage: 1, //当前页数
      pageSize: 4, //当前页记录数
      total: 0, //总条数
    };
  },
  methods: {
    loadBlogList() {
      this.axios.get("/blog/blogList/" + this.isDraft).then((res) => {
        this.tableData = res.data.blogList;
        this.loading = false;
        this.total = this.tableData.length;
      });
    },
    preview(row) {
      this.$router.push("./BlogDetail/" + row.blogId);
    },
    edit(row) {
      this.$router.push("./edit/" + row.blogId);
    },
    handleSizeChange(val) {
      this.currentPage = 1;
      this.pageSize = val;
    },
    handleCurrentChange(val) {
      this.currentPage = val;
    },
  },
  mounted() {
    this.loadBlogList();
  },
};
</script>

<style>
</style>
